﻿@using Abs.Core.Models.User
@model IEnumerable<Abs.Core.Models.Blog.Post>

@{
    ViewBag.Title = "Index";
    if((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.User)
    {
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    else
    {
        Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
    }
    
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            User
        </th>
        <th>
            Category
        </th>
        <th>
            Title
        </th>
        <th>
            Date
        </th>
        <th>
            Status
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.User.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Category.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Date)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Status.Title)
        </td>
        <td>
            @if ((string) this.Session["Email"] == item.UserEmail || 
                (int) this.Session["Role"] == (int) RoleEnum.Admin)
            {
                @Html.ActionLink("Edit", "Edit", new {id = item.PostId}) 
                <span> | </span>
            }
            
            @Html.ActionLink("Details", "Details", new { id=item.PostId }) 
            
            @if (String.IsNullOrEmpty((string)this.Session["Email"]) ||
                       (int)this.Session["Role"] == (int)RoleEnum.Admin)
            {
                <span> | </span>
                @Html.ActionLink("Delete", "Delete", new {id = item.PostId})
            }
        </td>
    </tr>
}

</table>
